package com.wad.manager.controller;

import com.wad.entity.product.Category;
import com.wad.manager.service.CategoryService;
import com.wad.vo.common.Result;
import com.wad.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author wad
 * @date 2023/12/05 14:20
 * @project e-commerce
 **/
@RestController
@RequestMapping("/admin/product/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;



    //分类的列表方法，每次查询一层数据，根据parent_id进行查询
    @GetMapping("/getCategoryList/{id}")
    public Result getCategoryList(@PathVariable("id") Long id){
        List<Category> categoryList=categoryService.findCategoryList(id);
        return Result.build(categoryList, ResultCodeEnum.SUCCESS);
    }

    //导出
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }


    //导入
    @PostMapping("/importData")
    public Result importData(MultipartFile file){
        //获取上传文件
        categoryService.importData(file);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
